package interfaze;

import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

public class menuPopUp extends JPopupMenu implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JMenuItem itAbrir, itImportar, itAbrirPW;
	ListWindow padre;

	public menuPopUp(ListWindow lW) {
		padre = lW;

		itAbrir = new JMenuItem("Abrir");
		add(itAbrir);
		itImportar = new JMenuItem("Importar");
		add(itImportar);
		itAbrirPW = new JMenuItem("Abrir ventana de reproduccion");
		add(itAbrirPW);

		itAbrir.addActionListener(this);
		itImportar.addActionListener(this);
		itAbrirPW.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		JFileChooser fc = new JFileChooser();
		if (e.getSource().equals(itAbrir)) {
			this.setVisible(false);
			fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
			int returnVal = fc.showOpenDialog(this);
			if (returnVal == JFileChooser.APPROVE_OPTION) {
				File file = fc.getSelectedFile();
				System.out.println("abriendo: " + file.getName());
				PlayWindow w = new PlayWindow(padre, file);
				w.setVisible(true);
			}
		} else if (e.getSource().equals(itImportar)) {
			this.setVisible(false);
			fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			int returnVal = fc.showOpenDialog(this);
			if (returnVal == JFileChooser.APPROVE_OPTION) {
				File file = fc.getSelectedFile();
				System.out.println("abriendo: " + file.getName());
			}
		} else if (e.getSource().equals(itAbrirPW)) {
			PlayWindow pW = new PlayWindow(padre, null);
			pW.setLocation(padre.getX() + padre.getWidth() + 20, padre.getY());
			pW.setVisible(true);
			this.setVisible(false);
			padre.player = pW;
		}
	}

}
